package com.power.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.power.domain.Notice;
import com.power.model.Result;
import com.power.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop")
public class noticeController {
    @Autowired
    private NoticeService noticeService;

    @GetMapping("/notice/page")
    public Result getNoticePage(@RequestParam Long current, @RequestParam Long size
            , @RequestParam(required = false) String title
            , @RequestParam(required = false) Integer status,
                                @RequestParam(required = false) Integer isTop) {
        Page<Notice> page = new Page<>(current, size);
        Page<Notice> page1 = noticeService.getNoticePage(page, title, status, isTop);

        return Result.success(page1);
    }

    @PostMapping("notice")
    public Result addNotice(@RequestBody Notice notice)
    {
        return noticeService.addNotice(notice)? Result.success("添加成功"):Result.fail(303,"添加失败");
    }
    @GetMapping("/notice/info/{id}")
    public  Result getNoticeById(@PathVariable Long id)
    {
        return Result.success(noticeService.getById(id));
    }
    @PutMapping("/notice")
    public  Result updateNotice(@RequestBody Notice notice)
    {
        return noticeService.updateById(notice)? Result.success("修改成功"):Result.fail(303,"修改失败");
    }
    @DeleteMapping("/notice/{id}")
    public  Result updateNotice(@PathVariable Long id)
    {
        return noticeService.DeleteById(id)? Result.success("删除成功"):Result.fail(303,"已公布删除失败");
    }
}
